package HUZ;

public class Test2 {
    private static  Object loker=new Object();

    private static  Object loker2=new Object();
    private static  Object loker3=new Object();


    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            synchronized (loker){

                Thread thread1=new Thread(()->{
                    synchronized (loker2){
                        System.out.print("A");
                        loker2.notify();
                    }
                });
               thread1.start();

                Thread thread2=new Thread(()->{
                    synchronized (loker2){
                        try {
                            loker2.wait();
                            System.out.print("B");
                            synchronized (loker3){
                                loker3.notify();
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }}
                });
                thread2.start();

                Thread thread3=new Thread(()->{
                    synchronized (loker3){
                        try {
                            loker3.wait();
                            System.out.println("B");
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                });
                thread3.start();
            }
        }
    }

    public static void main3(String[] args) throws InterruptedException {

        for (int i = 0; i < 10; i++) {
            synchronized (loker){
                //A
                Thread thread=new Thread(()-> System.out.print("A"));
                thread.start();

//                thread.join();
                //B
                Thread thread2=new Thread(()-> {
                    try {
                        thread.join();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.print("B");
                });
                thread2.start();

//                thread2.join();
                //C
                Thread thread3=new Thread(()->{
                    try {
                        thread2.join();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("C");
                });
                thread3.start();
                thread3.join();
            }
        }


    }
}
